$(function() {
    var bdbInnerDomainRecordList = {
        defData: {
            innerDomainId: bdbMain.getUrlParams()['id']
        },

        /* 页面状态 */
        pageState: {
            noData: 'def' // search: 没有匹配的结果; def: 暂无记录.
        },

        /* 添加 */
        addEvent: function() {
            var _this = this,
                formVerify;

            // 第一步表单验证.
            formVerify = $('#bdb-innerdomainrecord-masteradd-form').validate({
                // onkeyup: false,
                errorElement: "div",
                errorPlacement: function (error, element) {
                    error.addClass("help-block");
                    if (element.prop("type") === "checkbox" || element.prop("type") === "radio") {
                        error.appendTo(element.parents(".bdb-vc"));
                    } else {
                        error.insertAfter(element);
                    }
                },
                submitHandler: function(form, e) {
                    e.preventDefault();
                    _this.addSave(form, formVerify);
                }
            });

            // 添加(master).
            $('#bdb-innerdomainrecord-masteradd').off('click').on('click', function() {
                _this.addDefDataProc(formVerify); // 默认数据处理.
            });

            // 添加(master)取消.
            $('#innerdomainrecord-masteradd-cancel').off('click').on('click', function() {
                _this.resetAddForm(formVerify, 'cancel');
            });
        },
        addDefDataProcTpl: function(data) {
            var linesTpl = '',
                domainListTpl = '',
                formEle = $('#bdb-innerdomainrecord-masteradd-form');

            // 线路.
            $.each(data.lineList, function(i, n) {
                linesTpl += '<li data-id="' + i + '">\
                            <span class="left checkNo"></span>\
                            <span class="right">' + n + '</span>\
                            </li>';
            });
            formEle.find('.lines-list ul').html(linesTpl);
            formEle.find('.bdb-innerdomainrecord-form-lineid-container').bdbLinesSelect();

            // 记录值.
            $.each(data.ipList, function(i, n) {
                domainListTpl += '<li class="bdb-ellipsis" data-id="' + n.ip_id + '">\
                                 ' + n.ip + '&nbsp;-&nbsp;' + n.server_area + '&nbsp;-&nbsp;' + n.server_name + '</li>';
            });
            domainListTpl += '<li class="bdb-ellipsis bdb-hide" id="js-recordselect-null" data-id="">没有匹配的数据</li>';
            formEle.find('.record-list ul').html(domainListTpl);
            formEle.find('.bdb-innerdomainrecord-form-record-container').bdbRecordSelect();

            bdbMain.mLSleep({loading: false}, function() {
                formEle.fadeIn();
            });
        },
        addDefDataProc: function(formVerify) {
            var _this = this;
            bdbMain.mLRManag({mask: true, loading: true});
            $.post('/InnerDomain/innerDomainRecordInit', function(response) {
                if (response.code == 0) {
                    _this.addDefDataProcTpl(response.data);
                } else {
                    bdbMain.mLSleep({mask: false, loading: false, alert: {type: 2, msg: response.msg}});
                }
            }, 'json');
        },
        addSave: function(form, formVerify) {
            var _this = this,
                form = $(form),
                params = form.serialize() + '&innerDomainId=' + _this.defData.innerDomainId;

            // 请求已发出.
            if (!bdbMain.ajaxInfo.state) {
                bdbMain.mLRManag({alert: {type: 2, msg: bdbMain.ajaxInfo.text}});
                return ;
            }

            // 发送请求.
            bdbMain.ajaxInfo.state = 0; // 加锁.
            bdbMain.mLRManag({mask: true, maskUp: 101, loading: true});
            $.post('/InnerDomain/addMasterRecord', params, function(response) {
                if (response.code == 0) {
                    _this.resetAddForm(formVerify);
                    bdbMain.mLSleep({maskDown: 99, loading: false, alert: {type: 1, msg: '添加成功.'}}, function() {
                        bdbMain.mLSleep({}, function() {
                            _this.list();
                        });
                    });
                } else {
                    bdbMain.mLSleep({maskDown: 99, loading: false, alert: {type: 2, msg: response.msg}});
                }

                bdbMain.ajaxInfo.state = 1; // 释放锁.
            });
        },
        resetAddForm: function(formVerify, type) {
            var form = $('#bdb-innerdomainrecord-masteradd-form');

            form.find('.form-lines-layer, .form-record-layer').text('请选择');
            form[0].reset();
            formVerify.resetForm();
            form.hide();

            if (type == 'cancel') {
                bdbMain.mLRManag({mask: false});
            }
        },

        /* 列表 */
        listEvent: function() {
            var _this = this;
            $('.bdb-list').off('click.listEvent').on('click.listEvent', function(e) {
                var ele = $(e.target),
                    parentEle = ele.parents('.bdb-list-row'),
                    id = parentEle.attr('data-id'),
                    type = parentEle.attr('data-type'),
                    state = parentEle.attr('data-state');

                if (ele.hasClass('js-bdb-innerdomainrecord-edit')) { // 编辑.
                    _this.listEdit(id, type, ele);
                } else if (ele.hasClass('js-bdb-innerdomainrecord-del')) { // 删除.
                    _this.listDel(id, type);
                } else if (ele.hasClass('js-innerdomainrecord-slaveadd')) { // 添加-备
                    _this.listSlaveAdd(id, parentEle);
                } else if (ele.hasClass('js-bdb-innerdomainrecord-onoff')) { // 启用、暂停.
                    _this.listOnoff(id, state, parentEle)
                } else if (ele.attr('id') == 'innerdomainrecord-edit-cancel') { // 编辑-取消
                    $('#bdb-innerdomainrecord-edit-form').remove();
                    bdbMain.mLRManag({mask: false});
                } else if (ele.attr('id') == 'innerdomainrecord-slaveadd-cancel') { // 添加(备)-取消
                    $('#bdb-innerdomainrecord-slaveadd-form').remove();
                    bdbMain.mLRManag({mask: false});
                }
            });
        },
        listSlaveAdd: function(id, parentEle) {
            var _this = this;
            bdbMain.mLRManag({mask: true, loading: true});
            $.post('/InnerDomain/innerDomainRecordInit', function(response) {
                if (response.code == 0) {
                    var slaveAddHtml = _this.listSlaveAddTpl(id, parentEle, response.data),
                        slaveAddFormEle;

                    bdbMain.mLSleep({loading: false}, function() {
                        parentEle.after(slaveAddHtml);
                        _this.listSlaveAddVerify();
                        slaveAddFormEle = $('#bdb-innerdomainrecord-slaveadd-form');
                        slaveAddFormEle.find('.bdb-innerdomainrecord-form-record-container').bdbRecordSelect();
                        slaveAddFormEle.fadeIn();

                        // 修正弹出位置.
                        var scrollTopVal = $('.bdb-list').scrollTop();
                        if ((slaveAddFormEle.position().top + slaveAddFormEle.height()) > $('.bdb-list').height()) {
                            $('.bdb-list').scrollTop(scrollTopVal + slaveAddFormEle.height() + 29);
                        }
                    });
                } else {
                    bdbMain.mLSleep({mask: false, loading: false, alert: {type: 2, msg: response.msg}});
                }
            }, 'json');
        },
        listSlaveAddTpl: function(id, ele,  data) {
            var tpl = '',
                recordListHtml = '';

            $.each(data.ipList, function(i, n) {
                recordListHtml += '<li class="bdb-ellipsis" data-id="' + n.ip_id + '">\
                                  ' + n.ip + '&nbsp;-&nbsp;' + n.server_area + '&nbsp;-&nbsp;' + n.server_name + '</li>';
            });
            recordListHtml += '<li class="bdb-ellipsis bdb-hide" id="js-recordselect-null" data-id="">没有匹配的数据</li>';

            tpl += '<form class="bdb-hide" id="bdb-innerdomainrecord-slaveadd-form">\
                        <input type="hidden" name="masterRecordId" value="' + id + '">\
                        <div class="form-group bdb-clearfix">\
                            <div class="bdb-innerdomainrecord-add-col-1 bdb-f-l">\
                                <div class="bdb-text-align-c left">备</div>\
                            </div>\
                            <div class="bdb-innerdomainrecord-add-col-2 bdb-f-l bdb-p-r">\
                                <img class="bdb-up-arrow-s1" src="/static/imgs/global/add-items-arrow.svg">\
                                <div id="bdb-innerdomainrecord-line-text">' + ele.find('.bdb-mx-w-col-2').text() + '</div>\
                            </div>\
                            <div class="bdb-innerdomainrecord-add-col-3 bdb-f-l bdb-p-r">\
                                <img class="bdb-up-arrow-s1" src="/static/imgs/global/add-items-arrow.svg">\
                                <div class="bdb-innerdomainrecord-form-record-container">\
                                    <input class="form-record" id="ipid-slaveadd" name="ipId" type="text" autocomplete="off" \
                                        data-rule-required="true" data-msg-required="请选择记录值">\
                                    <div class="bdb-form-select-wrapper bdb-mouse-hover">\
                                        <div class="top-arrow"></div>\
                                        <div class="form-record-layer bdb-ellipsis">请选择</div>\
                                        <div></div>\
                                        <div class="bdb-hide record-list">\
                                            <div class="search">\
                                                <img class="bdb-mouse-hover" id="search-btn" src="/static/imgs/global/search-white.svg">\
                                                <input type="text" id="record-list-search-input" autocomplete="off" placeholder="请输入要搜索的域名">\
                                            </div>\
                                            <ul>' + recordListHtml + '</ul>\
                                        </div>\
                                        <div class="bottom-arrow"></div>\
                                    </div>\
                                </div>\
                            </div>\
                            <div class="bdb-innerdomainrecord-add-col-4 bdb-f-l bdb-p-r bdb-v-hide">&nbsp;</div>\
                            <div class="bdb-innerdomainrecord-add-col-5 bdb-f-l">\
                                <button class="bdb-btn bdb-btn-444858-s1" type="submit">确定</button>\
                                <button class="bdb-btn bdb-btn-444858-s1" id="innerdomainrecord-slaveadd-cancel" type="button">取消</button>\
                            </div>\
                        </div>\
                    </form>';

            return tpl;
        },
        listSlaveAddVerify: function() {
            var _this = this;
            $('#bdb-innerdomainrecord-slaveadd-form').validate({
                // onkeyup: false,
                errorElement: "div",
                errorPlacement: function (error, element) {
                    error.addClass("help-block");
                    if (element.prop("type") === "checkbox" || element.prop("type") === "radio") {
                        error.appendTo(element.parents(".bdb-vc"));
                    } else {
                        error.insertAfter(element);
                    }
                },
                submitHandler: function(form, e) {
                    e.preventDefault();
                    _this.listSlaveAddSave(form);
                }
            });
        },
        listSlaveAddSave: function(form) {
            var _this = this,
                form = $(form);

            // 请求已发出.
            if (!bdbMain.ajaxInfo.state) {
                bdbMain.mLRManag({alert: {type: 2, msg: bdbMain.ajaxInfo.text}});
                return ;
            }

            // 发送请求.
            bdbMain.ajaxInfo.state = 0; // 加锁.
            bdbMain.mLRManag({mask: true, maskUp: 101, loading: true});
            $.post('/InnerDomain/addBakRecord', form.serialize(), function(response) {
                if (response.code == 0) {
                    form.remove();
                    bdbMain.mLSleep({maskDown: 99, mask: false, loading: false, alert: {type: 1, msg: '备添加成功.'}}, function() {
                        bdbMain.mLSleep({}, function() {
                            _this.list();
                        });
                    });
                } else {
                    bdbMain.mLSleep({maskDown: 99, loading: false, alert: {type: 2, msg: response.msg}});
                }

                bdbMain.ajaxInfo.state = 1; // 释放锁.
            });
        },
        listEdit: function(id, type, ele) {
            var _this = this;
            bdbMain.mLRManag({mask: true, loading: true});
            $.post('/InnerDomain/innerDomainRecordInfo', {
                recordId: id,
                type: type
            }, function(response) {
                if (response.code == 0) {
                    _this.listEditProc(id, response.data, ele);
                } else {
                    bdbMain.mLSleep({mask: false, loading: false, alert: {type: 2, msg: response.msg}});
                }
            }, 'json');
        },
        listEditProc: function(id, data, ele) {
            var _this = this;

            $.post('/InnerDomain/innerDomainRecordInit', function(response) {
                $('#bdb-innerdomainrecord-edit-form').remove();
                if (response.code == 0) {
                    var editHtml = _this.listEditProcTpl(data, response.data);
                    bdbMain.mLSleep({loading: false}, function() {
                        ele.parents('.bdb-list-row').after(editHtml);
                        var formEle = $('#bdb-innerdomainrecord-edit-form');
                        formEle.find('.bdb-innerdomainrecord-form-record-container').bdbRecordSelect();
                        formEle.fadeIn();
                        _this.listEditVerify();

                        // 修正弹出位置.
                        var scrollTopVal = $('.bdb-list').scrollTop();
                        if ((formEle.position().top + formEle.height()) > $('.bdb-list').height()) {
                            $('.bdb-list').scrollTop(scrollTopVal + formEle.height() + 29);
                        }
                    });
                } else {
                    bdbMain.mLSleep({mask: false, loading: false, alert: {type: 2, msg: response.msg}});
                }
            }, 'json');
        },
        listEditProcTpl: function(editRowData, initData) {
            var tpl = '',
                masterBakText = '主',
                recordText = '',
                recordId = 0,
                recordListHtml = '',
                ttlHide = '',
                ttlVal = 0;

            if (editRowData.type == 'bak') {
                masterBakText = '备';
                recordId = editRowData.recordInfo.bak_record_id;
                ttlHide = 'bdb-v-hide';
            } else {
                recordId = editRowData.recordInfo.master_record_id;
                ttlVal = editRowData.recordInfo.ttl;
            }

            $.each(initData.ipList, function(i, n) {
                recordListHtml += '<li class="bdb-ellipsis" data-id="' + n.ip_id + '">\
                                  ' + n.ip + '&nbsp;-&nbsp;' + n.server_area + '&nbsp;-&nbsp;' + n.server_name + '</li>';

                if (editRowData.recordInfo.ip_id == n.ip_id) {
                    recordText = n.ip + '&nbsp;-&nbsp;' + n.server_area + '&nbsp;-&nbsp;' + n.server_name;
                }
            });
            recordListHtml += '<li class="bdb-ellipsis bdb-hide" id="js-recordselect-null" data-id="">没有匹配的数据</li>';

            tpl += '<form class="bdb-hide" id="bdb-innerdomainrecord-edit-form">\
                        <input type="hidden" name="recordId" value="' + recordId + '">\
                        <input type="hidden" name="type" value="' + editRowData.type + '">\
                        <div class="form-group bdb-clearfix">\
                            <div class="bdb-innerdomainrecord-add-col-1 bdb-f-l">\
                                <div class="bdb-text-align-c left">' + masterBakText + '</div>\
                            </div>\
                            <div class="bdb-innerdomainrecord-add-col-2 bdb-f-l bdb-p-r">\
                                <img class="bdb-up-arrow-s1" src="/static/imgs/global/add-items-arrow.svg">\
                                <div id="bdb-innerdomainrecord-line-text">' + editRowData.recordInfo.record_line_name + '</div>\
                            </div>\
                            <div class="bdb-innerdomainrecord-add-col-3 bdb-f-l bdb-p-r">\
                                <img class="bdb-up-arrow-s1" src="/static/imgs/global/add-items-arrow.svg">\
                                <div class="bdb-innerdomainrecord-form-record-container">\
                                    <input class="form-record" id="ipId-edit" name="ipId" type="text" autocomplete="off" \
                                        value="' + editRowData.recordInfo.ip_id + '" data-rule-required="true" data-msg-required="请选择记录值">\
                                    <div class="bdb-form-select-wrapper bdb-mouse-hover">\
                                        <div class="top-arrow"></div>\
                                        <div class="form-record-layer bdb-ellipsis">' + recordText + '</div>\
                                        <div></div>\
                                        <div class="bdb-hide record-list">\
                                            <div class="search">\
                                                <img class="bdb-mouse-hover" id="search-btn" src="/static/imgs/global/search-white.svg">\
                                                <input type="text" id="record-list-search-input" autocomplete="off" placeholder="请输入要搜索的ip">\
                                            </div>\
                                            <ul>' + recordListHtml + '</ul>\
                                        </div>\
                                        <div class="bottom-arrow"></div>\
                                    </div>\
                                </div>\
                            </div>\
                            <div class="bdb-innerdomainrecord-add-col-4 bdb-f-l bdb-p-r">\
                                <img class="bdb-up-arrow-s1 ' + ttlHide + '" src="/static/imgs/global/add-items-arrow.svg">\
                                <input class="form-ttl ' + ttlHide + '" id="ttl-edit" name="ttl" type="text" autocomplete="off" value="' + ttlVal + '" \
                                    data-rule-required="true" data-msg-required="请输入TTL" data-rule-digits="true" data-msg-digits="请输入正整数">\
                            </div>\
                            <div class="bdb-innerdomainrecord-add-col-5 bdb-f-l">\
                                <button class="bdb-btn bdb-btn-444858-s1" type="submit">确定</button>\
                                <button class="bdb-btn bdb-btn-444858-s1" id="innerdomainrecord-edit-cancel" type="button">取消</button>\
                            </div>\
                        </div>\
                    </form>';

            return tpl;
        },
        listEditVerify: function() {
            var _this = this,
                formVerify;

            formVerify = $('#bdb-innerdomainrecord-edit-form').validate({
                // onkeyup: false,
                errorElement: "div",
                errorPlacement: function (error, element) {
                    error.addClass("help-block");
                    if (element.prop("type") === "checkbox" || element.prop("type") === "radio") {
                        error.appendTo(element.parents(".bdb-vc"));
                    } else {
                        error.insertAfter(element);
                    }
                },
                submitHandler: function(form, e) {
                    e.preventDefault();
                    _this.listEditSave(form);
                }
            });
        },
        listEditSave: function(form) {
            var _this = this,
                form = $(form);

            // 请求已发出.
            if (!bdbMain.ajaxInfo.state) {
                bdbMain.mLRManag({alert: {type: 2, msg: bdbMain.ajaxInfo.text}});
                return ;
            }

            // 发送请求.
            bdbMain.ajaxInfo.state = 0; // 加锁.
            bdbMain.mLRManag({mask: true, maskUp: 101, loading: true});
            $.post('/InnerDomain/editInnerDomainRecord', form.serialize(), function(response) {
                if (response.code == 0) {
                    form.remove();
                    bdbMain.mLSleep({maskDown: 99, mask: false, loading: false, alert: {type: 1, msg: '编辑成功.'}}, function() {
                        bdbMain.mLSleep({}, function() {
                            _this.list();
                        });
                    });
                } else {
                    bdbMain.mLSleep({maskDown: 99, loading: false, alert: {type: 2, msg: response.msg}});
                }

                bdbMain.ajaxInfo.state = 1; // 释放锁.
            });
        },
        listOnoff: function(id, state, rowEle) {
            var _this = this,
                stateText = '暂停',
                strategyText = '放出',
                stateStr = 'enable',
                stateVal = 1,
                recordStateText = '启用';

            if (state == 1) {
                stateText = '启用';
                stateStr = 'disable';
                stateVal = 0;
                recordStateText = '暂停';
                strategyText = '不放出';
            }

            bdbMain.confirm({
                textInfo: {
                    content: '确定要' + recordStateText + '这条记录？',
                    btn: {}
                },
                // note: true,
                params: {
                    url: '/InnerDomain/switchInnerDomainRecord',
                    data: {
                        id: id,
                        stateStr: stateStr,
                        stateVal: stateVal,
                        stateText: stateText,
                        recordStateText: recordStateText,
                        rowEle: rowEle,
                        strategyText: strategyText
                    }
                },
                callback: function(ele, params) {
                    _this.listOnoffCallbackProc(ele, params);
                }
            });
        },
        listOnoffCallbackProc: function(ele, params) {
            var _this = this;
            ele.hide();

            // 请求已发出.
            if (!bdbMain.ajaxInfo.state) {
                bdbMain.mLRManag({alert: {type: 2, msg: bdbMain.ajaxInfo.text}});
                return ;
            }

            // 发送请求.
            bdbMain.ajaxInfo.state = 0; // 加锁.
            bdbMain.mLRManag({mask: true, loading: true});
            $.post(params.url, {
                masterRecordId: params.data.id,
                status: params.data.stateStr
            }, function(response) {
                if (response.code == 0) {
                    bdbMain.mLSleep({mask: false, loading: false, alert: {type: 1, msg: params.data.recordStateText + '成功'}}, function() {
                        params.data.rowEle.attr('data-state', params.data.stateVal);
                        params.data.rowEle.find('.bdb-mx-w-col-6').text(params.data.recordStateText);
                        params.data.rowEle.find('.bdb-mx-w-col-8').text(params.data.strategyText);
                        params.data.rowEle.find('.js-bdb-innerdomainrecord-onoff').text(params.data.stateText);
                    });
                } else {
                    bdbMain.mLSleep({mask: false, loading: false, alert: {type: 2, msg: response.msg}});
                }

                bdbMain.ajaxInfo.state = 1; // 释放锁.
            });
        },
        listDel: function(id, type) {
            var _this = this;

            bdbMain.confirm({
                textInfo: {
                    content: '确定要删除这条记录？',
                    btn: {}
                },
                // note: true,
                params: {
                    url: '/InnerDomain/deleteInnerDomainRecord',
                    data: {
                        id: id,
                        type: type
                    }
                },
                callback: function(ele, params) {
                    _this.listDelCallbackProc(ele, params);
                }
            });
        },
        listDelCallbackProc: function(ele, params) {
            var _this = this;
            ele.hide();

            // 请求已发出.
            if (!bdbMain.ajaxInfo.state) {
                bdbMain.mLRManag({alert: {type: 2, msg: bdbMain.ajaxInfo.text}});
                return ;
            }

            // 发送请求.
            bdbMain.ajaxInfo.state = 0; // 加锁.
            bdbMain.mLRManag({mask: true, loading: true});
            $.post(params.url, {
                recordId: params.data.id,
                type: params.data.type
            }, function(response) {
                if (response.code == 0) {
                    bdbMain.mLSleep({mask: false, loading: false, alert: {type: 1, msg: '删除成功'}}, function() {
                        bdbMain.mLSleep({}, function() {
                            _this.list();
                        });
                    });
                } else {
                    bdbMain.mLSleep({mask: false, loading: false, alert: {type: 2, msg: response.msg}});
                }

                bdbMain.ajaxInfo.state = 1; // 释放锁.
            });
        },
        listProc: function(data) {
            var tpl = '';
            $.each(data.masterList, function(i, n) {
                // 主.
                var ipStateText = '启用',
                    stateText = '暂停',
                    recordStateText = '启用'
                    putText = '放出';

                if (n.ip_status == 0) {
                    ipStateText = '暂停';
                }

                if (n.status == 0) {
                    stateText = '启用';
                    recordStateText = '暂停';
                    putText = '不放出';
                }

                tpl += '<div class="bdb-list-row" data-id="' + n.master_record_id + '" data-type="master" data-state="' + n.status + '">\
                            <div class="bdb-mx-w-col-1">\
                                <div class="left">主</div>\
                                <div class="right">\
                                    <div class="bdb-option-btn bdb-p-r bdb-mgn-t-10">\
                                        <a class="js-innerdomainrecord-slaveadd" href="javascript:void(0);">备</a>\
                                        <span class="js-innerdomainrecord-slaveadd"></span>\
                                    </div>\
                                </div>\
                            </div>\
                            <div class="bdb-mx-w-col-2">' + n.record_line_name + '</div>\
                            <div class="bdb-mx-w-col-3">' + n.record_type + '</div>\
                            <div class="bdb-mx-w-col-4 bdb-ellipsis bdb-text-align-l">' + n.master_record + '</div>\
                            <div class="bdb-mx-w-col-5">' + ipStateText + '</div>\
                            <div class="bdb-mx-w-col-6">' + recordStateText + '</div>\
                            <div class="bdb-mx-w-col-7">' + n.monitor_status + '</div>\
                            <div class="bdb-mx-w-col-8">' + putText + '</div>\
                            <div class="bdb-mx-w-col-9">' + n.ttl + '</div>\
                            <div class="bdb-mx-w-col-10">' + n.create_time + '</div>\
                            <div class="bdb-mx-w-col-11 bdb-text-align-l">\
                                <div class="bdb-option-btn bdb-p-r bdb-mgn-t-10">\
                                    <a class="js-bdb-innerdomainrecord-onoff" href="javascript:void(0);">' + stateText + '</a>\
                                    <div class="v-line-ffa007"></div>\
                                    <a class="bdb-mgn-l--1 js-bdb-innerdomainrecord-edit" href="javascript:void(0);">编辑</a>\
                                    <div class="v-line-ffa007"></div>\
                                    <a class="bdb-f-c-c8baac bdb-mgn-l--1 js-bdb-innerdomainrecord-del" href="javascript:void(0);">删除</a>\
                                </div>\
                            </div>\
                        </div>';

                // 备不存在.
                if (typeof n.bakList != 'object' && !n.bakList.length) {
                    return ;
                }

                // 备.
                $.each(n.bakList, function(i1, n1) {
                    var slaveIpStateText = '启用',
                        slaveStateText = '启用',
                        slavePutText = '不放出';

                    if (n1.ip_status == 0) {
                        slaveIpStateText = '暂停';
                    }

                    if (n1.status == 0) {
                        slaveStateText = '暂停';
                    } else if (n1.status == 1) {
                        slavePutText = '放出';
                    } else if (n1.status == 2) {
                        slaveStateText = '备用';
                    }

                    tpl += '<div class="bdb-list-row" data-id="' + n1.bak_record_id + '" data-type="bak">\
                                <div class="bdb-mx-w-col-1">\
                                    <div class="left">备</div>\
                                </div>\
                                <div class="bdb-mx-w-col-2">' + n1.record_line_name + '</div>\
                                <div class="bdb-mx-w-col-3">' + n.record_type + '</div>\
                                <div class="bdb-mx-w-col-4 bdb-ellipsis bdb-text-align-l">' + n1.bak_record + '</div>\
                                <div class="bdb-mx-w-col-5">' + slaveIpStateText + '</div>\
                                <div class="bdb-mx-w-col-6">' + slaveStateText + '</div>\
                                <div class="bdb-mx-w-col-7">' + n1.monitor_status + '</div>\
                                <div class="bdb-mx-w-col-8">' + slavePutText + '</div>\
                                <div class="bdb-mx-w-col-9">' + n.ttl + '</div>\
                                <div class="bdb-mx-w-col-10">' + n1.create_time + '</div>\
                                <div class="bdb-mx-w-col-11 bdb-text-align-l">\
                                    <div class="bdb-option-btn bdb-p-r bdb-mgn-t-10">\
                                        <a class="js-bdb-innerdomainrecord-edit" href="javascript:void(0);">编辑</a>\
                                        <div class="v-line-ffa007"></div>\
                                        <a class="bdb-f-c-c8baac bdb-mgn-l--1 js-bdb-innerdomainrecord-del" href="javascript:void(0);">删除</a>\
                                    </div>\
                                </div>\
                            </div>';
                });

            });

            return tpl;
        },
        list: function(obj) {
            var _this = this,
                obj = obj || {page: 1};

            _this.pageState.page = obj.page;
            bdbMain.mLRManag({mask: true, loading: true});

            // 获取列表.
            $.post('/InnerDomain/innerDomainRecordList', {
                innerDomainId: _this.defData.innerDomainId
            }, function(response) {
                var totalRowCnt = 0,
                    listHtml = '';

                if (response.code == 0) {
                    totalRowCnt = parseInt(response.data.totalCount) > 0 ? parseInt(response.data.totalCount) : 0;
                    listHtml = _this.listProc(response.data);
                    _this.listNull(totalRowCnt);
                    $('.bdb-list').html(listHtml);
                    bdbMain.mLSleep({mask: false, loading: false});

                    // 分页插件.
                    $("#js-bdb-creatPage").bdbPagination({
                        totalRowCnt: totalRowCnt,
                        currentPage: _this.pageState.page,
                        pageSize: _this.defData.pageSize
                    });
                    $('.bdb-record-cnt').html(bdbMain.pageInfo.recordCnt.replace('{cnt}', totalRowCnt));
                } else {
                    bdbMain.mLSleep({mask: false, loading: false, alert: {type: 2, msg: response.msg}});
                }
			    $('.check-all-icon').removeClass('checkAll').addClass('checkNone'); // 撤销全选.
            });
        },
        listNull: function(totalRowCnt) {
            var noResult = $('.bdb-no-result'),
                noSearchRecord = $('.bdb-no-search-record');

            if (totalRowCnt <= 0) {
                if (this.pageState.noData == 'search') { // 查询.
                    noResult.hide();
                    noSearchRecord.show();
                } else { // 暂无记录.
                    noResult.show();
                    noSearchRecord.hide();
                }
            } else {
                noResult.hide();
                noSearchRecord.hide();
            }
        },

        /* 屏幕高度适应 */
        contentSizeResize: function () {
            $(window).resize(function() {
                $('.bdb-list').bdbScreenH(3);
            });
        },

        /* 初始化 */
        init: function() {
            var _this = this;

            _this.addEvent(); // 添加.
            _this.list(); // 加载列表.
            _this.listEvent(); // 列表操作事件.
			_this.contentSizeResize(); //内容区域屏幕适应.

            $('.bdb-list').bdbScreenH(3); // 右侧列表区域自适应.
        }
    };

    bdbInnerDomainRecordList.init();
});
